package com.nodecollege.cloud.core;

import com.nodecollege.cloud.common.exception.NCException;
import com.nodecollege.cloud.service.impl.deal.*;

/**
 * 聊天类型枚举
 *
 * @author LC
 * @date 23:36 2020/2/26
 **/
public enum ChatTypeEnum {
    CHAT_GROUP(1, "聊天群消息", ChatGroupServiceImpl.class),
    CHAT_FRIEND(2, "好友聊天消息", ChatFriendServiceImpl.class),
    CONNECT(3, "第一次(或重连)初始化连接", ChatConnectServiceImpl.class),
    GROUP_USER(4, "获取群组用户信息", ChatGroupUserServiceImpl.class),
    SIGNED(5, "消息签收", ChatSignedServiceImpl.class),
    GET_RECORD(6, "获取历史消息", ChatGetRecordServiceImpl.class),
    UPDATE_GROUP_USER(8, "修改群用户信息", ChatUpdateGroupUserServiceImpl.class),
    UPDATE_GROUP(9, "修改群信息", ChatUpdateGroupServiceImpl.class),
    ADD_GROUP_USER(10, "添加群用户", ChatAddGroupUserServiceImpl.class),
    DEL_GROUP_USER(11, "删除群用户", ChatDelGroupUserServiceImpl.class);

    private Integer chatType;
    private String chatTypeName;
    private Class chatTypeClass;

    ChatTypeEnum(Integer chatType, String chatTypeName, Class chatTypeClass) {
        this.chatType = chatType;
        this.chatTypeName = chatTypeName;
        this.chatTypeClass = chatTypeClass;
    }

    public static Class getClassByType(Integer chatType) {
        if (chatType == null) {
            throw new NCException("", "类型不能为空");
        } else {
            ChatTypeEnum[] chatTypeEnums = values();
            for (ChatTypeEnum chatTypeEnum : chatTypeEnums) {
                if (chatTypeEnum.getChatType().equals(chatType)) {
                    return chatTypeEnum.getChatTypeClass();
                }
            }
            throw new NCException("", "不匹配的类型");
        }
    }

    public Integer getChatType() {
        return this.chatType;
    }

    public String getChatTypeName() {
        return this.chatTypeName;
    }

    public Class getChatTypeClass() {
        return this.chatTypeClass;
    }
}
